using System.Windows.Forms;
using RollManager.Library;
using RollManager.Forms.MenuDialogs;

namespace RollManager.Forms.DetailsPanels
{
    public partial class ServersDetailsPanel : UserControl, DetailsPanel
    {
        private Server Server
        {
            get
            {
                return (Server) serverList.SelectedItem;
            }
        }

        public ServersDetailsPanel()
        {
            InitializeComponent();
            refreshList();
        }

        public void Save()
        {
        }

        private void renameToolStripMenuItem_Click( object sender, System.EventArgs e )
        {
            RenameServerDialog dialog = new RenameServerDialog( Server );
            if( dialog.ShowDialog() == DialogResult.OK )
            {
                refreshList();
            }
        }

        private void refreshList()
        {
            serverList.DataSource = Database.GetServers();
            serverList.DisplayMember = ItemBase.NAME_PROPERTY;
        }

        private void deleteToolStripMenuItem_Click( object sender, System.EventArgs e )
        {
            if(MessageBox.Show( "Are you sure you wish to delete this?", "Confirm Deleeion", MessageBoxButtons.YesNo,
                             MessageBoxIcon.Question, MessageBoxDefaultButton.Button1 ) == DialogResult.Yes)
            {
                Database.DeleteServer( Server.Id );
                refreshList();
            }
        }
    }
}